/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package defender;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;

/**
 *
 * @author Shane
 */
public class SimpleTest extends BasicGame {

    static int height = 480;
    static int width = 640;
    static boolean fullscreen = false;
    static boolean showFPS = true;
    static String title = "Slick Basic Game Template";
    static int fpslimit = 60;
    Image plane = null;
    float x = 400;
    float y = 300;
    float scale = 1;

    public SimpleTest(String title) {
        super(title);
    }

    public void init(GameContainer gc) throws SlickException {
        plane = new Image("data/plane.png");
    }

    public void update(GameContainer gc, int delta) throws SlickException {
        Input input = gc.getInput();

        if (input.isKeyDown(Input.KEY_A)) {
            plane.rotate(-0.2f * delta);
        }

        if (input.isKeyDown(Input.KEY_D)) {
            plane.rotate(0.2f * delta);
        }

        if (input.isKeyDown(Input.KEY_W)) {
            float hip = 0.4f * delta;

            float rotation = plane.getRotation();

            x += hip * Math.sin(Math.toRadians(rotation));
            y -= hip * Math.cos(Math.toRadians(rotation));
        }
        if (input.isKeyDown(Input.KEY_S)) {
            float hip = -0.4f * delta;

            float rotation = plane.getRotation();

            x += hip * Math.sin(Math.toRadians(rotation));
            y -= hip * Math.cos(Math.toRadians(rotation));
        }

        if (input.isKeyDown(Input.KEY_2)) {
            scale += (scale >= 5.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth() / 2.0f * scale, plane.getHeight() / 2.0f * scale);
        }
        if (input.isKeyDown(Input.KEY_1)) {
            scale -= (scale <= 1.0f) ? 0 : 0.1f;
            plane.setCenterOfRotation(plane.getWidth() / 2.0f * scale, plane.getHeight() / 2.0f * scale);
        }
    }

    public void render(GameContainer gc, Graphics g) throws SlickException {
        plane.draw(x, y, scale);
    }

    public static void main(String[] args) throws SlickException {
        AppGameContainer app = new AppGameContainer(new SimpleTest(title));
        app.setDisplayMode(width, height, fullscreen);
        app.setSmoothDeltas(true);
        app.setTargetFrameRate(fpslimit);
        app.setShowFPS(showFPS);
        app.start();
    }
}
